using System.Collections.Generic;
using System.Threading.Tasks;
using JGSY.CMS.LowCode.Platform.Domain.Entities;

namespace JGSY.CMS.LowCode.Platform.Domain.Interfaces
{
    /// <summary>
    /// 表单仓储接口
    /// 提供表单数据访问操作，支持表单管理和提交数据存储
    /// </summary>
    public interface IFormRepository
    {
        /// <summary>
        /// 获取所有表单记录
        /// </summary>
        /// <returns>表单实体列表</returns>
        Task<IEnumerable<Form>> GetAllAsync();
        
        /// <summary>
        /// 根据ID获取表单记录
        /// </summary>
        /// <param name="id">表单标识符</param>
        /// <returns>表单实体，如果未找到则返回null</returns>
        Task<Form?> GetByIdAsync(long id);

        /// <summary>
        /// 根据标识符获取表单记录
        /// </summary>
        /// <param name="identifier">表单标识符</param>
        /// <returns>表单实体，如果未找到则返回null</returns>
        Task<Form?> GetByIdentifierAsync(string identifier);

        /// <summary>
        /// 获取活跃表单
        /// </summary>
        /// <returns>活跃表单列表</returns>
        Task<IEnumerable<Form>> GetActiveFormsAsync();

        /// <summary>
        /// 分页获取表单列表
        /// </summary>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="keyword">搜索关键词</param>
        /// <param name="status">状态过滤</param>
        /// <returns>分页结果</returns>
        Task<(IEnumerable<Form> Items, int TotalCount)> GetPagedAsync(
            int pageIndex, 
            int pageSize, 
            string? keyword = null, 
            byte? status = null);
        
        /// <summary>
        /// 添加新表单
        /// </summary>
        /// <param name="entity">要添加的表单实体</param>
        /// <returns>添加操作任务</returns>
        Task AddAsync(Form entity);
        
        /// <summary>
        /// 更新表单信息
        /// </summary>
        /// <param name="entity">更新后的表单实体</param>
        /// <returns>更新操作任务</returns>
        Task UpdateAsync(Form entity);
        
        /// <summary>
        /// 删除表单
        /// </summary>
        /// <param name="id">表单标识符</param>
        /// <returns>删除操作任务</returns>
        Task DeleteAsync(long id);

        /// <summary>
        /// 批量删除表单
        /// </summary>
        /// <param name="ids">表单ID列表</param>
        /// <returns>删除数量</returns>
        Task<int> BatchDeleteAsync(IEnumerable<long> ids);

        /// <summary>
        /// 检查表单标识符是否存在
        /// </summary>
        /// <param name="identifier">表单标识符</param>
        /// <param name="excludeId">排除的表单ID</param>
        /// <returns>是否存在</returns>
        Task<bool> IdentifierExistsAsync(string identifier, long? excludeId = null);

        /// <summary>
        /// 增加提交次数
        /// </summary>
        /// <param name="id">表单ID</param>
        /// <returns>是否更新成功</returns>
        Task<bool> IncrementSubmissionCountAsync(long id);

        /// <summary>
        /// 获取表单统计信息
        /// </summary>
        /// <param name="id">表单ID</param>
        /// <returns>统计信息</returns>
        Task<object> GetFormStatisticsAsync(long id);

        /// <summary>
        /// 获取在指定时间范围内的活跃表单
        /// </summary>
        /// <param name="startTime">开始时间</param>
        /// <param name="endTime">结束时间</param>
        /// <returns>活跃表单列表</returns>
        Task<IEnumerable<Form>> GetActiveFormsInTimeRangeAsync(DateTime? startTime, DateTime? endTime);
    }
}
